package cn.lhjl.day08.JDBC;

import java.sql.*;
import java.util.Collections;

public class JdbcDemo06 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.210.129:1521:Xe", "HR", "123456");
            stmt = conn.createStatement();
            String sql="select * from student";
            rs = stmt.executeQuery(sql);
            while (rs.next()){
                int sid = rs.getInt("sid");
                String sname = rs.getString("sname");
                int sage = rs.getInt("sage");
                System.out.println(sid+"---"+sname+"---"+sage);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            if (rs!=null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (stmt!=null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (conn!=null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
